package com.imti.retrofitweatherdemo.fragment;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import com.imti.retrofitweatherdemo.logic.NewsModelListItem;
import java.util.List;

public class NewsDataModel extends ViewModel
{

    private static NewsDataModel newsDataModel;

    private MutableLiveData<List<NewsModelListItem>> newsDataList = new MutableLiveData<>();

    public static NewsDataModel getInstance()
    {
        if (null == newsDataModel)
        {
            newsDataModel = new ViewModelProvider
                                    .NewInstanceFactory()
                                .create(NewsDataModel.class);
        }

        return newsDataModel;
    }

    public LiveData<List<NewsModelListItem>> dataReady()
    {
        return newsDataList;
    }

    public void setNewModelList(List<NewsModelListItem> modelList)
    {
        if (null != newsDataList.getValue())
        {
            newsDataList.getValue().clear();
        }

        newsDataList.setValue(modelList);
    }
}
